<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseXrays.class.php';

Class Xrays {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjXrays = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objXrays = new BaseXrays();
			$objXrays->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objXrays->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objXrays->setSubject( ( true == isset( $row["subject"] ) ) ? $row["subject"] : 'NULL' );
			$objXrays->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objXrays->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objXrays->setChargeTypeId( ( true == isset( $row["charge_type_id"] ) ) ? $row["charge_type_id"] : 'NULL' );
			$objXrays->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objXrays->setChargeAmount( ( true == isset( $row["charge_amount"] ) ) ? $row["charge_amount"] : 'NULL' );
			$objXrays->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objXrays->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objXrays->setDocumentAttachmentPath( ( true == isset( $row["document_attachment_path"] ) ) ? $row["document_attachment_path"] : 'NULL' );
			$objXrays->setAttachmentId( ( true == isset( $row["attachment_id"] ) ) ? $row["attachment_id"] : 'NULL' );
			$objXrays->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjXrays, $objXrays );
		}
		return $arrobjXrays;
	}
	public function fetchAllXrays() {
		$result = $this->connection->RunQuery("SELECT * FROM XRAYS");
		$arrobjXrays = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objXrays = new BaseXrays();
			$objXrays->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objXrays->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objXrays->setSubject( ( true == isset( $row["subject"] ) ) ? $row["subject"] : 'NULL' );
			$objXrays->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objXrays->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objXrays->setChargeTypeId( ( true == isset( $row["charge_type_id"] ) ) ? $row["charge_type_id"] : 'NULL' );
			$objXrays->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objXrays->setChargeAmount( ( true == isset( $row["charge_amount"] ) ) ? $row["charge_amount"] : 'NULL' );
			$objXrays->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objXrays->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objXrays->setDocumentAttachmentPath( ( true == isset( $row["document_attachment_path"] ) ) ? $row["document_attachment_path"] : 'NULL' );
			$objXrays->setAttachmentId( ( true == isset( $row["attachment_id"] ) ) ? $row["attachment_id"] : 'NULL' );
			$objXrays->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjXrays, $objXrays);
		}
		return $arrobjXrays;
	}
	public function fetchAllXraysByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM XRAYS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjXrays = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objXrays->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objXrays->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objXrays->setSubject( ( true == isset( $row["subject"] ) ) ? $row["subject"] : 'NULL' );
			$objXrays->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objXrays->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objXrays->setChargeTypeId( ( true == isset( $row["charge_type_id"] ) ) ? $row["charge_type_id"] : 'NULL' );
			$objXrays->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objXrays->setChargeAmount( ( true == isset( $row["charge_amount"] ) ) ? $row["charge_amount"] : 'NULL' );
			$objXrays->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objXrays->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objXrays->setDocumentAttachmentPath( ( true == isset( $row["document_attachment_path"] ) ) ? $row["document_attachment_path"] : 'NULL' );
			$objXrays->setAttachmentId( ( true == isset( $row["attachment_id"] ) ) ? $row["attachment_id"] : 'NULL' );
			$objXrays->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjXrays, $objXrays );
		}
		return $arrobjXrays;
	}

	public function fetchXraysById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM XRAYS WHERE id = " . $intId );
			$objXrays = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objXrays = new BaseXrays();
			$objXrays->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objXrays->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objXrays->setSubject( ( true == isset( $row["subject"] ) ) ? $row["subject"] : 'NULL' );
			$objXrays->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objXrays->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objXrays->setChargeTypeId( ( true == isset( $row["charge_type_id"] ) ) ? $row["charge_type_id"] : 'NULL' );
			$objXrays->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objXrays->setChargeAmount( ( true == isset( $row["charge_amount"] ) ) ? $row["charge_amount"] : 'NULL' );
			$objXrays->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objXrays->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objXrays->setDocumentAttachmentPath( ( true == isset( $row["document_attachment_path"] ) ) ? $row["document_attachment_path"] : 'NULL' );
			$objXrays->setAttachmentId( ( true == isset( $row["attachment_id"] ) ) ? $row["attachment_id"] : 'NULL' );
			$objXrays->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
		}
		return $objXrays;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from xrays order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endXrays(){
		$this->connection->CloseMysql();
	}

}